<?php
namespace Plu\Library\Services\Tga\Baoming;

use Plu\Library\Services\ServiceBase;

class RedisService extends ServiceBase {
    const KEY_OF_APP_INFO = "baoming:app:%s";

    const KEY_OF_FORM_INFO = "baoming:form:%s";

    const KEY_OF_SIGNUP    = "baoming:app:user:%s";

    public function __construct() {
        $this->_redis = $this->getRedis('webcache');
    }

    public function getFormInfo($appkey) {
       return json_decode($this->_redis->get(sprintf(self::KEY_OF_FORM_INFO, $appkey)), true);

    }

    public function getAppInfo($appid) {
        return json_decode($this->_redis->get(sprintf(self::KEY_OF_APP_INFO, $appid)), true);
    }

    /**
     *  如果用户已经注册 把信息存放到 baoming:$appkey 这个hash中。
     */
    public function set($suffix, $uid, $data){
        $key = sprintf(self::KEY_OF_SIGNUP, $suffix);

        $this->_redis->hSet($key, $uid, $data);
    }

    /**
     *  获取用户报名的信息
     */
    public function get($suffix, $uid){
        $key = sprintf(self::KEY_OF_SIGNUP, $suffix);

        return $this->_redis->hGet($key, $uid);
    }

    public function del($suffix, $uid){
        $key = sprintf(self::KEY_OF_SIGNUP, $suffix);

        return $this->_redis->hDel($key, $uid);
    }

        /**
     *  获取用户报名的信息
     */
    public function getAll($suffix){
        $key = sprintf(self::KEY_OF_SIGNUP, $suffix);

        return $this->_redis->hGetAll($key);
    }
}
?>
